<head>
<!-- Copyright (C) 2020 mn

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. 
--> 
<title>quasi 0.2</title>
<style>
div {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
textarea {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
</style>
</head>

<body>
<span id="progrun">
</span>
<div id="dtop" style="position: absolute; top: 1%; left: 1%; width: 98%; height: 35%;"><br>&nbsp;display window</div>
<textarea id="dleft" style="position: absolute; top: 38%; left: 1%; width: 32%; height: 58%;">

# import window 

hello # cls
there print end
hello print
</textarea>
<div id="dmid" style="position: absolute; top: 38%; left: 35%; width: 64%; height: 58%;"
onclick="javascript:runimport();"><br>&nbsp;program editor (not implemented yet)<br><br>&nbsp;click here to run program in import/export window on left<br><br></div>

<script>
dtop.style.background = 'white'; dtop.style.bordercolor = 'black'; dtop.style.border = 'solid';

dleft.style.background = 'white'; dleft.style.bordercolor = 'black'; dleft.style.border = 'solid';
// dleft.innerHTML = "<textarea style='width: 100%; height: 100%;'></textarea>";

dmid.style.background = 'white'; dmid.style.bordercolor = 'black'; dmid.style.border = 'solid';

function q_cls() { 
    if (progrun.innerHTML == "<!-- -->") { return 0; } 
    dtop.innerHTML = ""; 
    }

function outd(p) {
    dtop.innerHTML += "<span style='color: orange;'>" + p + "</span><br>\n";
    }

function q_end() { 
    progrun.innerHTML = "<!-- -->";
    }

function q_print(p) { 
    if (progrun.innerHTML == "<!-- -->") { return 0; } 
    dtop.innerHTML = dtop.innerHTML + p + "<br>\n"; 
    }

function left(s, l) {
    return s.substring(0, l);
    }

function right(s, l) {
    return s.substring(s.length-l, s.length);
    }

cmds = {
    cls: "q_cls(); ",
    end: "q_end(); ",
    print: "q_print(0); "
    }

function runimport() { 
    parsed = textparse(); 
    if (parsed != "") { 
        dtop.innerHTML = parsed.split("\n").join("<br>\n");
        eval(parsed); 
        } 
    }

function textparse() { 
    q_cls();
    progrun.innerHTML = "";
    var p = "";
    var petc = "";
    var getcmd = "";
    var cc = dleft.innerHTML + "\n";
    var codeout = "";
    var inquotes = 0;
    var commented = 0;
    for(count = 0; count < cc.length; count++) {
        p = cc.substring(count, count + 1);
        if (p == "#") { 
            commented = 1; 
            }
        if (p == "\"") { 
            if (inquotes == 1) {
                inquotes = 0;
                } 
            else {
                inquotes = 1;
                }
            }
        if (commented == 0 && inquotes == 0 && left(petc, 1) != "#") {
            if (p == " " || p == "\n") { 
                if (p == " ") { 
                    p = ""; 
                    }
                if (petc != "") {
                    eval("getcmd=cmds." + petc + ";");
                    if (getcmd != undefined) { codeout += getcmd; }
                    petc = "";
                    }	
                }
            }
        if (p == "\n") { 
            commented = 0;
            inquotes = 0;
            if (left(petc, 1) == "#") {
                codeout += "// " + petc + "\n"; 
                }
            else {
                codeout += "\n";
                }
            petc = ""; }
        else {
            petc += p;
            }
        }
    return codeout;
    }

dtop.innerHTML = "<br>" + document.title + "<br>Copyright (C) 2020 mn<br><br>This program is free software: you can redistribute it and/or modify it under the terms of the <a href='gpl-3.0.txt'>GNU General Public License</a> as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br><br>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.<br><br>You should have received a copy of the GNU General Public License along with this program. If not, see <a href='https://www.gnu.org/licenses/'>https://www.gnu.org/licenses/</a>.";

</script>
</body>
